package com.atde._05_behavioral_design_patterns.state.app;


/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._05_behavioral_design_patterns.state.app
 * @Author: Del
 * @CreateTime: 2025-06-30  11:36
 * @Description: 状态模式 --- 抽奖活动
 * @Version: 1.0
 */
public class RaffleActivity {
    // state 表示活动当前状态
    State state = null;
    // 奖品数量
    int count = 0;

    // 四个属性, 表示四种状态
    State noRaffleState = new NoRaffleState(this);
    State canRaffleState = new CanRaffleSatte(this);
    State dispenseState = new DispenseState(this);
    State dispenseOutState = new DispenseOutState(this);

    /**
     * 1. 初始化当前的状态 noRaffleState （即不能抽象状态）
     * 2. 初始化奖品数量
     * @param count
     */
    public RaffleActivity(int count) {
        this.count = count;
        // 初始化时，设置为没有抽奖的状态
        state = getNoRaffleState();
    }

    public State getNoRaffleState() {
        return noRaffleState;
    }

    public State getCanRaffleState() {
        return canRaffleState;
    }

    public State getDispenseState() {
        return dispenseState;
    }

    public State getDispenseOutState() {
        return dispenseOutState;
    }

    public void debuctMoney() {
        state.deductMoney();
    }

    public void raffle() {
        // 状态判断
        if (state.raffle()) {
            // 领取奖品
            state.dispensePrize();
        }
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    // 每领取一次奖品，count值减1
    public int getCount() {
        int curConut = count;
        count--;
        return curConut;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void setNoRaffleState(State noRaffleState) {
        this.noRaffleState = noRaffleState;
    }

    public void setCanRaffleState(State canRaffleState) {
        this.canRaffleState = canRaffleState;
    }

    public void setDispenseState(State dispenseState) {
        this.dispenseState = dispenseState;
    }

    public void setDispenseOutState(State dispenseOutState) {
        this.dispenseOutState = dispenseOutState;
    }
}
